package edu.java.texbooks.scjp.collections.test03.comparison.arrays.comparator;

import java.util.Comparator;

import edu.java.texbooks.scjp.collections.test03.comparison.arrays.Student;

public class StudentComparatorByMarks implements Comparator<Student> {
	@Override
	public int compare(Student student1, Student student2) {
		// check input
		if (student1 == null) {
			throw new IllegalArgumentException(
					"Incorrect input of first student object "
							+ "in implementation of Comparator by FacNum. ");
		}

		if (student2 == null) {
			throw new IllegalArgumentException(
					"Incorrect input of second student object "
							+ "in implementation of Comparator by FacNum. ");
		}

		// return
		if (student1.getMarks() < student2.getMarks()) {
			return -1;
		} else if (student1.getMarks() > student2.getMarks()) {
			return 1;
		} else {
			return 0;
		}

		// return student1.getMarks() - student2.getMarks();
	}
}
